﻿using System;
using System.Collections.Generic;

namespace eProject.Model
{
    public class ScheduleItem
    {
        public double ManHours { get; private set; }

        public Period Period { get; private set; }

        private readonly IList<string> _employeesEmails;

        public IEnumerable<string> EmployeesEmails { get { return _employeesEmails; }}

        public ScheduleItem(Period period, double manHours)
        {
            Period = period;
            ManHours = manHours;
            _employeesEmails = new List<string>(0);
        }

        public ScheduleItem(Period period, double manHours, IEnumerable<string> employeesEmails)
        {
            Period = period;
            ManHours = manHours;
            _employeesEmails = new List<string>(employeesEmails);
        }

        public ScheduleItem(Period period, double manHours, string employeeEmail)
        {
            Period = period;
            ManHours = manHours;
            _employeesEmails = new List<string>{employeeEmail};
        }

        public bool IsApplicable(DateTime date, string employeeEmail)
        {
            return IsApplicable(date) && IsApplicable(employeeEmail);
        }

        public bool IsApplicable(DateTime date)
        {
            return Period.Contains(date);
        }

        public bool IsApplicable(string employeeEmail)
        {
            return _employeesEmails.Count == 0 || _employeesEmails.Contains(employeeEmail);
        }                  

        public void ChangeEmail(string oldEmployeeEmail, string newEmployeeEmail)
        {
            if (!_employeesEmails.Contains(oldEmployeeEmail)) return;
            _employeesEmails.Remove(oldEmployeeEmail);
            _employeesEmails.Add(newEmployeeEmail);
        }
    }
}
